package com.csw.shuanfa.CodeImprove.designPattern;

//抽象组件
interface Component {
    void operation();
}

/**
 * 装饰器模式
 */
public class DecoratorD {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Component component = new ConcreateComponent();
        component.operation();

        Decorator decorator = new ConcreateDecorator(component);
        decorator.operation();
    }
}

//具体组件
class ConcreateComponent implements Component {

    @Override
    public void operation() {
        System.out.println("基础操作");
    }
}

//抽象装饰器
class Decorator implements Component {
    protected Component component;

    public Decorator(Component component) {
        this.component = component;
    }

    @Override
    public void operation() {
        component.operation();
    }
}

//具体装饰器
class ConcreateDecorator extends Decorator {
    public ConcreateDecorator(Component component) {
        super(component);
    }

    public void operation() {
        super.operation();
        addedBehavior();
    }

    public void addedBehavior() {
        System.out.println("添加额外的行为");
    }
}
